*/
private $mTrxWriteDuration = 0.0;
+ /** @var array Map of (name => 1) for locks obtained via lock() */
+ private $mNamedLocksHeld = array();
+
/** @var IDatabase|null Lazy handle to the master DB this server replicates from */
private $lazyMasterHandle;
$msg = __METHOD__ . ": lost connection to $server; reconnected";
wfDebugLog( 'DBPerformance', "$msg:\n" . wfBacktrace( true ) );
- if ( $hadTrx ) {
+ if ( $hadTrx || $this->mNamedLocksHeld ) {
# Leave $ret as false and let an error be reported.
# Callers may catch the exception and continue to use the DB.
$this->reportQueryError( $lastError, $lastErrno, $sql, $fname, $tempIgnore );
}
public function lock( $lockName, $method, $timeout = 5 ) {
+ $this->mNamedLocksHeld[$lockName] = 1;
+
return true;
}
public function unlock( $lockName, $method ) {
+ unset( $this->mNamedLocksHeld[$lockName] );
+
return true;
}
$row = $this->fetchObject( $result );
if ( $row->lockstatus == 1 ) {
+ parent::lock( $lockName, $method, $timeout ); // record
return true;
- } else {
- wfDebug( __METHOD__ . " failed to acquire lock\n" );
-
- return false;
}
+
+ wfDebug( __METHOD__ . " failed to acquire lock\n" );
+
+ return false;
}
/**
$result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method );
$row = $this->fetchObject( $result );
- return ( $row->lockstatus == 1 );
+ if ( $row->lockstatus == 1 ) {
+ parent::unlock( $lockName, $method ); // record
+ return true;
+ }
+
+ wfDebug( __METHOD__ . " failed to release lock\n" );
+
+ return false;
}
private function makeLockName( $lockName ) {
"SELECT pg_try_advisory_lock($key) AS lockstatus", $method );
$row = $this->fetchObject( $result );
if ( $row->lockstatus === 't' ) {
+ parent::lock( $lockName, $method, $timeout ); // record
return true;
} else {
sleep( 1 );
}
}
+
wfDebug( __METHOD__ . " failed to acquire lock\n" );
return false;
$result = $this->query( "SELECT pg_advisory_unlock($key) as lockstatus", $method );
$row = $this->fetchObject( $result );
- return ( $row->lockstatus === 't' );
+ if ( $row->lockstatus === 't' ) {
+ parent::unlock( $lockName, $method ); // record
+ return true;
+ }
+
+ wfDebug( __METHOD__ . " failed to release lock\n" );
+
+ return false;
}
/**